package com.java.mapper;

import com.java.dto.SelectEmployeeAndEmployeeDTO;
import com.java.dto.SelectEmployeeAndEmployeesDTO;
import com.java.entity.Department;
import com.java.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DepartmentMapper {
    // 先用部门Id查询出部门信息 再查询出部门员工
    @Select("select * from dept;")
    @Results({
            @Result(column = "deptno",property = "employee",many = @Many(select = "com.java.mapper.DepartmentMapper.selectEmployeeById"))
    })
    List<SelectEmployeeAndEmployeeDTO> selectEmployeeAndEmployees(int deptId);

    // 查询全部员工及所属部门信息
    @Select("select * from emp;")
    @Results({
            @Result(column = "deptno",property = "department",one = @One(select = "com.java.mapper.DepartmentMapper.selectDepartmentById"))
    })
    List<SelectEmployeeAndEmployeesDTO> selectEmployeeAndEmployee();

    // 用部门id查询员工
    @Select("select * from emp where deptno in(#{id});")
    List<Employee> selectEmployeeById(int id);

    // 用部门id查询部门信息
    @Select("select * from dept where deptno in(#{deptno});")
    List<Department> selectDepartmentById(int deptno);
}
